package com.dp.appi.dao.impl;

import com.dp.appi.dao.ModuleDao;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * Created by xiaoji on 2016/5/13.
 * 模块
 */
@Component
public class ModuleDaoImpl extends BaseDaoImpl implements ModuleDao {
    /**
     * 获取模块列表
     *
     * @param name 材料模块名称
     * @param s    开始序列
     * @param n    获取条数
     * @return
     */
    @Override
    public List<Map<String, Object>> moduleList(String name, String versionid,Integer s, Integer n) {
        String sql="select cmm.module_id,cmm.module_material_id as material_id,cmm.material_number,cmm.erp_id,cmm.erp_code,cmm.`name`,cmm.big_category," +
                "cmm.middle_category,cmm.small_category,cmm.spec,cmm.unit,cmm.unit_weight,cmm.estimate_price," +
                "cmm.original,cmm.thumb,cmm.height,cmm.length,cmm.num,cmm.consume_steel,cmm.consume_concrete," +
                "cmm.remark" +
                " from c_module_material cmm , c_module cm "+
                " where cmm.parent_id is NULL ";
                sql+=" and cmm.module_id =cm.module_id  ";
                if(!StringUtils.isEmpty(name)){
                    sql+=" and cmm.name like '%"+name+"%' ";
                }
               if(! versionid.equals("0"))
                {
                   sql+=" and cm.codeset_version_id = '"+versionid+"'";
                }
        sql+=" order by cmm.module_material_id asc limit ?,?";
        return getJdbcTemplate().query(sql,new Object[]{s,n},getColumnMapRowMapper());
    }
}
